﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AMS.DataAccess.Sys.Filters;
using AMS.DataAccess.Filter;
using AMS.DataAccess;
using AMS.DataAccess.Sys.BO;

public partial class User_ucSearchUser : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (txtSearchName.Text == "输入查询名称")
        {
            txtSearchName.Text = "";
        }
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        OnUserFilterChanged();
    }

    public UserFilter GetUserFilter()
    {
        UserFilter filter = new UserFilter();
        if (!string.IsNullOrEmpty(txtName.Text))
        {
            filter.Name = new StringFilterField(txtName.Text, StringOperations.Like);
        }
        if (!string.IsNullOrEmpty(txtLoginName.Text))
        {
            filter.LoginName = new StringFilterField(txtLoginName.Text, StringOperations.Like);
        }
        if (!string.IsNullOrEmpty(txtWorkNumber.Text))
        {
            filter.WorkNumber = new StringFilterField(txtWorkNumber.Text, StringOperations.Like);
        }
        if (drpAttoney.SelectedIndex > 0)
        {
            switch (drpAttoney.SelectedIndex)
            {
                case 1:
                    filter.IsTrademarkAttoney = new BooleanFilterField(false);
                    filter.IsPatentAttoney = new BooleanFilterField(false);
                    break;

                case 2:
                    filter.IsPatentAttoney = new BooleanFilterField(true);
                    break;

                case 3:
                    filter.IsTrademarkAttoney = new BooleanFilterField(true);
                    break;

                default:
                    throw new NotFiniteNumberException("未完成");
            }
        }
        if (drpSex.SelectedIndex > 0)
        {
            if (drpSex.SelectedIndex == 1)
            {
                filter.Sex = new EnumFilterField<SexEnum>(SexEnum.Male);
            }
            else
            {
                filter.Sex = new EnumFilterField<SexEnum>(SexEnum.Female);
            }
        }

        return filter;
    }

    public event EventHandler FilterChanged;
    protected void OnUserFilterChanged()
    {
        if (FilterChanged != null)
        {
            FilterChanged(this, EventArgs.Empty);
        }
    }
}
